def plusOne(digits):
    num = digits.pop() + 1
    if num >= 10:
        if digits:
            digits = plusOne(digits)
        else:
            digits.insert(0, 1)
        digits = digits + [num % 10]
    else:
        digits.append(num)
    return digits


print(plusOne([1, 2, 3]))  # [1,2,4]
print(plusOne([4, 3, 2, 1]))  # [4,3,2,2]
print(plusOne([0]))  # [1]
print(plusOne([9, 9, 9]))  # [1, 0, 0, 0]
print(plusOne([6, 9, 9]))  # [7, 0, 0]
